package org.bluedream.core.module.controller.bill.stkIn;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.bluedream.comm.base.BaseController;
import org.bluedream.comm.utils.RestResult;
import org.bluedream.core.config.advice.RsaSecurityParameter;
import org.bluedream.core.module.entity.bill.stkIn.StkInBack;
import org.bluedream.core.module.entity.bill.stkIn.dtl.StkInBackDtl;
import org.bluedream.core.module.entity.goods.Goods;
import org.bluedream.core.module.service.bill.stkIn.StkInBackService;
import org.bluedream.core.module.service.bill.stkIn.dtl.StkInBackDtlService;
import org.bluedream.core.module.service.goods.GoodsService;
import org.bluedream.core.utils.configUtil.GoalConfigUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @ClassName StkInBackController
 * @Description TODO
 * @Author foxsand
 * @Data 2021-11-19 9:03
 * @Version
 */
@Slf4j
@Controller
@RequestMapping(value = "${adminPath}/stkInBack")
public class StkInBackController extends BaseController {

    @Resource
    private StkInBackService stkInBackService;

    @Resource
    private StkInBackDtlService stkInBackDtlService;

    @Resource
    private GoodsService goodsService;

    @ModelAttribute
    public StkInBack get(String id){
        return stkInBackService.getById(id);
    }

    @RequiresPermissions("stkInBack:view")
    @RequestMapping(value = {"/list" , ""})
    public String list(StkInBack entity, Model model){
        model.addAttribute("pageSize" , GoalConfigUtil.getValueByKey("sys.page.size"));
        model.addAttribute("stkInBack" , entity);
        return "module/bill/stkIn/stkInBackList";
    }

    @RequiresPermissions("stkInBack:view")
    @RequestMapping("/form")
    public String form(StkInBack entity, Model model){
        model.addAttribute("stkInBack" , entity);
        return "module/bill/stkIn/stkInBackForm";
    }

/*
    @RequiresPermissions("stkInBack:view")
    @RequestMapping("/form4Dtl")
    public String form4Dtl(StkInBack entity, Model model){
        model.addAttribute("stkInBack" , entity);
        return "module/bill/stkIn/stkInDtlForm";
    }
*/

    @RequiresPermissions("stkInBack:view")
    @RequestMapping(value = "/goodsForm")
    public String goodsForm(Model model){
        model.addAttribute("pageSize" , GoalConfigUtil.getValueByKey("sys.page.size"));
        model.addAttribute("goods" , new Goods());
        return "module/goods/goodsSelect";
    }

    @RequiresPermissions("stkInBack:edit")
    @RequestMapping("/getGoods")
    @ResponseBody
    public RestResult getGoods(Goods entity){
        return goodsService.getOne(entity);
    }

    @RequiresPermissions("stkInBack:view")
    @RequestMapping("/findPage")
    @ResponseBody
    public IPage<StkInBack> findPage(@RsaSecurityParameter StkInBack entity){
        return stkInBackService.findPage(entity);
    }

    @RequiresPermissions("stkInBack:view")
    @RequestMapping("/findPage4Dtl")
    @ResponseBody
    public IPage<StkInBackDtl> findPage4Dtl(@RsaSecurityParameter StkInBack entity){
        return stkInBackDtlService.findPage(entity);
    }


    @RequiresPermissions("stkInBack:edit")
    @RequestMapping("/save")
    @ResponseBody
    public RestResult save(StkInBack entity){
        return stkInBackService.saveEntity(entity);
    }

    @RequiresPermissions("stkInBack:check")
    @RequestMapping("/check")
    @ResponseBody
    public RestResult check(StkInBack entity){
        return stkInBackService.check(entity);
    }
}
